/**
 * @param {number[]} nums
 * @return {number}
 */
var rob = function(nums) {
  let length = nums.length
  if (length === 0) {
    return 0
  }
  let dep = []
  dep.push(0, nums[0])
  for (let i = 2; i <= length; i++) {
    dep[i] = Math.max(dep[i - 1], dep[i - 2] + nums[i - 1])
  }
  return dep[length]
};
console.log(rob([1,2,3,1]));